#include "../myudp.h"


#define UDP_SERVER_IP   "192.168.31.13"
#define UDP_SERVER_PORT 50000

#define UDP_CLINT_IP   "192.168.31.13"
#define UDP_CLINT_PORT 60000


int main(int argc, char const *argv[])
{
    int Ret;
    char strSend[] = "Hi, UDP Server, this is UDP Clint";

    int UdpClintSockFd;
    Ret = UdpSelfBind( &UdpClintSockFd, UDP_CLINT_IP, UDP_CLINT_PORT );

    Ret = UdpSendto( UdpClintSockFd, strSend, strlen(strSend), 
                     UDP_SERVER_IP, UDP_SERVER_PORT );
    if( -1 == Ret )
    {
        perror( "fail UdpSendto" );
        return -1;
    }

    printf( "send to %s:%d : %s\n", UDP_SERVER_IP, UDP_SERVER_PORT, strSend );

    char strRecvBuff[1024] = {0};
    char strServerIP[100] = {0};
    int ServerPort = 0;

    Ret = UdpRecvfrom( UdpClintSockFd, strRecvBuff, sizeof(strRecvBuff), 
                       strServerIP, &ServerPort );
    if( -1 == Ret )
    {
        perror( "fail UdpRecvfrom" );
        return -1;
    }

    printf( "Received from %s : %d : %s\n", strServerIP, ServerPort, strRecvBuff );

    Ret = close( UdpClintSockFd );
    if( -1 == Ret )
    {
        perror( "fail close" );
        return -1;
    }

    return 0;
}
